#include "Fanuc/FanucCollectManager.h"
#include "Fanuc/FanucCollector.h"

FanucCollectManager::FanucCollectManager(/* args */):
    collector(nullptr)
{
}

FanucCollectManager::~FanucCollectManager()
{
    if(collector)
    {
        delete collector;
        collector = nullptr;
    }
    if(threadProcess.joinable())
    {
        threadProcess.join();
    }
}

void FanucCollectManager::init(const FANUC::fanucConnectInfo& info)
{
    _connectInfo = info;
}

void FanucCollectManager::start()
{
    if(!collector)
    {
        collector = new FanucCollector;
    }
    collector->init(_connectInfo);
    threadProcess = std::thread(&FanucCollector::start, collector);
}

void FanucCollectManager::stop()
{
    collector->stop();
}